package com.future.mayi.fragment;

import android.text.TextUtils;
import android.webkit.WebView;

import com.future.baselib.entity.DefaultResponse;
import com.future.baselib.utils.ApiCst;
import com.future.baselib.utils.HttpRequest;
import com.future.mayi.R;
import com.future.mayi.activity.BaseFragment;
import com.future.mayi.utils.HtmlFormat;

import org.json.JSONException;
import org.json.JSONObject;

import butterknife.BindView;

public class GoodsPurchaseProcessFragment extends BaseFragment {


    @BindView(R.id.web_view)
    WebView webView;


    @Override
    protected int getLayoutResource() {
        return R.layout.fragment_goods_purchase_process;
    }

    @Override
    protected void initView() {
        setData();
    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void initData() {

    }

    public void setData() {
        if (webView == null) return;
        new HttpRequest<DefaultResponse>()
                .with(getActivity())
                .setApiCode(ApiCst.getGmlc)
                .setListener(new HttpRequest.OnNetworkListener<DefaultResponse>() {
                    @Override
                    public void onSuccess(DefaultResponse response) {
                        String data = response.content;
                        if (!TextUtils.isEmpty(data)) {
                            JSONObject object = null;
                            try {
                                object = new JSONObject(data);
                                String info = object.optString("info");
                                if (info == null) return;
                                if (webView == null) return;
                                webView.loadDataWithBaseURL(null, HtmlFormat.getNewContent(info), "text/html", "utf-8", null);
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        }
                    }

                    @Override
                    public void onFail(String message, DefaultResponse response) {

                    }
                })
                .start(new DefaultResponse());
    }


}
